package bramar.all;

import java.awt.*;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.awt.List;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
 class Ttest extends JFrame{

	private int currentCard = 1;
	private JPanel cardPanel;
	private CardLayout cl;
	private ButtonGroup group;
        private JButton b1,b2,b3,b4,b11,b12,b13;
        private JPanel buttonPanel;
	private JRadioButton OracleToMySql;
	private JRadioButton OracleToAccess;
	private JRadioButton MySqlToOracle;
	private JRadioButton MySqlToAccess;
	private JRadioButton AccessToOracle;
	private JRadioButton AccessToMySql;
        private TextField tf1,tf2;
	private  List l1=new List(6);
        private  List l2=new List(6);
        private JPanel p2;
        private String s;
        
        Connection con;
	public Ttest() {

		setTitle("Card Layout Example");
		setSize(450, 450);
		cardPanel = new JPanel();

		cl = new CardLayout();
		cardPanel.setLayout(cl);
		JPanel p1 = new JPanel();
		//p1.setLayout(new FlowLayout());

		 p2 = new JPanel();
		JPanel p3 = new JPanel();
		//JPanel p4 = new JPanel();
	OracleToMySql=new JRadioButton("OracleToMySql");
	OracleToAccess=new JRadioButton("OracleToAccess");
	MySqlToOracle=new JRadioButton("MySqlToOracle");
	MySqlToAccess=new JRadioButton("MySqlToAccess");
	AccessToOracle=new JRadioButton("AccessToOracle");
	AccessToMySql=new JRadioButton("AccessToMySql");

		JLabel lab1 = new JLabel("OracleToMySql");
		JLabel lab2 = new JLabel("OracleToAccess");
		JLabel lab3 = new JLabel("MySqlToOracle");
		JLabel lab4 = new JLabel("MySqlToAccess");
		JLabel lab5 = new JLabel("AccessToOracle");
		JLabel lab6 = new JLabel("AccessToMySql");
p1.setLayout(new GridLayout(0, 1));
//Adding RadioButtons to first panel.

		p1.add(OracleToMySql);
		//p1.add(lab1);
		p1.add(OracleToAccess);
		//p1.add(lab2);		
		p1.add(MySqlToOracle);
		//p1.add(lab3);
		p1.add(MySqlToAccess);
		//p1.add(lab4);		
		p1.add(AccessToOracle);
		//p1.add(lab5);
		p1.add(AccessToMySql);
		//p1.add(lab6);

setLayout(new BorderLayout());
add(p1, BorderLayout.CENTER);
//creating ButtonGroup.
		
		group=new ButtonGroup();
		group.add(OracleToMySql);
		group.add(OracleToAccess);
		group.add(MySqlToOracle);
		group.add(MySqlToAccess);
		group.add(AccessToOracle);
		group.add(AccessToMySql);
                cardPanel.add(p1, "1");
//Registration process of RadioButtons.
       
    /*Jrdbutton jrd=new Jrdbutton();
    OracleToMySql.addItemListener(jrd);
    OracleToAccess.addItemListener(jrd);
    MySqlToOracle.addItemListener(jrd);
    MySqlToAccess.addItemListener(jrd);
    AccessToOracle.addItemListener(jrd);
    AccessToMySql.addItemListener(jrd);*/
    
JLabel lab9=new JLabel("Source DB:");
JLabel lab10=new JLabel("Target DB:");
p2.add(lab9);
tf1=new TextField(15);
tf2=new TextField(15);
p2.add(tf1);
p2.add(lab10);
p2.add(tf2);
tf1.setEditable(false);
tf2.setEditable(false);
l1.setMultipleMode(true);
JLabel lab7=new JLabel("Source DB Tables:");
p2.add(lab7);
p2.add(l1);
b1=new JButton(">");
b2=new JButton(">>");
b3=new JButton("<");
b4=new JButton("<<");
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
JLabel lab8=new JLabel("Transfered Tables from source DB:");
p2.add(lab8);
p2.add(l2);

 
 
		cardPanel.add(p2, "2");
  
		//cardPanel.add(p3, "3");
		//cardPanel.add(p4, "4");
                buttonPanel = new JPanel();
		b11 = new JButton("Previous");
		b12 = new JButton("Next");
                b13=new JButton("Transfer");
		buttonPanel.add(b11);
		buttonPanel.add(b12);
                buttonPanel.add(b13);
		b11.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (currentCard > 1) {
					currentCard -= 1;
					cl.show(cardPanel, "" + (currentCard));
                                         //buttonPanel.remove(b13);
                                        // buttonPanel.add(b11);
                                        }
			}
		});

		b12.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				   // buttonPanel.add(b13);
                                    //buttonPanel.remove(b12);
                            b11 = new JButton("Previous");
                                if(OracleToMySql.isSelected())
                                //ButtonModel selected=group.getSelection();
                                //String select=selected.toString();
                                //if(select.equals("OracleToMySql"))
                                {
                     try {
                        tf1.setText("Oracle");
                        repaint();
                        tf2.setText("MySql");
                        Class.forName("oracle.jdbc.driver.OracleDriver");
                        con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger");
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("select * from tab");
                        l1.removeAll();
                        l2.removeAll();
                        while(rs.next())
                        {                            
                            l1.add(rs.getString(1));
                        }
                    } catch (SQLException ex) {
                        ex.printStackTrace();
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    }
                                }else if(OracleToAccess.isSelected())
                                {
                               try {
                                    tf1.setText("Oracle");
                                    tf2.setText("Access");
                                    Class.forName("oracle.jdbc.driver.OracleDriver");
                        con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger");
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("select * from tab");
                        l1.removeAll();
                        l2.removeAll();
                        while(rs.next())
                        {
                                
                                l1.add(rs.getString(1));
                        }
                    } catch (SQLException ex1) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex1);
                    } catch (ClassNotFoundException ex1) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex1);
                    }
                                }else if(MySqlToOracle.isSelected())
                                {
                                try{
                                tf1.setText("MySql");
                                tf2.setText("Oracle");
                                Class.forName("org.gjt.mm.mysql.Driver");
                        con=DriverManager.getConnection("jdbc:mysql:///mydb1","root","root");
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("show tables from mydb1");
                        l1.removeAll();
                        l2.removeAll();
                        while(rs.next())
                        { 
                            l1.add(rs.getString(1));
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    }
                                }else if(MySqlToAccess.isSelected())
                                {
                                try{
                                    tf1.setText("MySql");
                                    tf2.setText("Access");
                        Class.forName("org.gjt.mm.mysql.Driver");
                        con=DriverManager.getConnection("jdbc:mysql:///mydb1","root","root");
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("show tables from mydb1");
                        l1.removeAll();
                        l2.removeAll();
                        while(rs.next())
                        {
                            l1.add(rs.getString(1));
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    }
                                    
                                }else if(AccessToOracle.isSelected())
                                {
                                try{
                                tf1.setText("Access");
                                tf2.setText("Oracle");
                                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        con=DriverManager.getConnection("jdbc:odbc:accdsn");
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("SELECT NAME FROM MSysObjects WHERE Type=1 AND NAME NOT LIKE 'MS%' ORDER BY NAME");
                        l1.removeAll();
                        l2.removeAll();
                        while(rs.next())
                        { 
                            l1.add(rs.getString(1));
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    }
                               
                                }else if(AccessToMySql.isSelected())
                                {

                              try{
                                  tf1.setText("Access");
                                  tf2.setText("MySql");
                               
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        con=DriverManager.getConnection("jdbc:odbc:accdsn");
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("SELECT NAME FROM MSysObjects WHERE Type=1 AND NAME NOT LIKE 'MS%' ORDER BY NAME");
                        l1.removeAll();
                        l2.removeAll();
                        while(rs.next())
                        { 
                            l1.add(rs.getString(1));
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                    }
                                }
                                if (currentCard < 4)
                                {
					currentCard += 1;
					cl.show(cardPanel, "" + (currentCard));
                                        p2.repaint();
                                        
                                }
                                
			}
		});
                b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ie) {
			 if(ie.getSource()==b1)
                        {
                    String s=l1.getSelectedItem(); 
                    
                        l2.add(s);
                        l1.remove(s);
                    
                        }	 
			}
		});
                
                 b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ie1) {
			if(ie1.getSource()==b2)
                {
                    String s[]=l1.getItems();
                    for(int i=0;i<s.length;i++)
                    {
                        l2.add(s[i]);
                        l1.remove(s[i]);
                    }
                }
			}
		});
                
                b3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ie2) {
			 if(ie2.getSource()==b3)
                        {
                    String s=l2.getSelectedItem();
                    
                        l1.add(s);
                        l2.remove(s);
                    
                        }	 
			}
		});
                b4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ie3) {
			 if(ie3.getSource()==b4)
                        {
                        String s[]=l2.getItems();
                        for(int i=0;i<s.length;i++)
                            {
                             l1.add(s[i]);
                             l2.remove(s[i]);
                            
                             }
                        }	 
			}
		});
                
                
                 
                
                 b13.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			if(e.getSource()==b13)
                        {
                            if(OracleToMySql.isSelected())
                            {
                                
                            String s[]=l2.getItems();
                            for(int i=0;i<s.length;i++)
                            {
                        try {
                            OracleToMySqlTable omt = new OracleToMySqlTable(s[i]);
                            OracleToMySqldata omd = new OracleToMySqldata(s[i]);
                        } catch (SQLException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                            
                            }
                            }else if(OracleToAccess.isSelected())
                            {
                                String s[]=l2.getItems();
                                for(int i=0;i<s.length;i++)
                                {
                        try {
                             OracleToAccessTable oat = new OracleToAccessTable(s[i]);
                            OracleToAccessdata oad = new OracleToAccessdata(s[i]);
                        } catch (SQLException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                            
                                }
                                }else if(MySqlToOracle.isSelected())
                            {
                                String s[]=l2.getItems();
                                for(int i=0;i<s.length;i++)
                                {
                        try {
                            MySqlToOracleTable mot = new MySqlToOracleTable(s[i]);
                            MySqlToOracledata mod = new MySqlToOracledata(s[i]);
                        } catch (SQLException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                                }
                                }else if(MySqlToAccess.isSelected())
                            {
                                String s[]=l2.getItems();
                                for(int i=0;i<s.length;i++)
                                {
                        try {
                            MySqlToAccessTable mat = new MySqlToAccessTable(s[i]);
                            MySqlToAccessdata mad = new MySqlToAccessdata(s[i]);
                        } catch (SQLException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                                }
                                }else if(AccessToOracle.isSelected())
                            {
                                     String s[]=l2.getItems();
                                for(int i=0;i<s.length;i++)
                                {
                        try {
                            AccessToOracleTable aot = new AccessToOracleTable(s[i]);
                            AccessToOracledata aod = new AccessToOracledata(s[i]);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (SQLException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                                }
                                }else if(AccessToMySql.isSelected())
                            {
                                 String s[]=l2.getItems();
                                for(int i=0;i<s.length;i++)
                                {
                        try {
                            AccessToMySqlTable amt = new AccessToMySqlTable(s[i]);
                            AccessToMySqldata amd = new AccessToMySqldata(s[i]);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (SQLException ex) {
                            Logger.getLogger(Ttest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                            }//for close
                            }//else-if close
                        }//if-main close
                        }//action performed
                    
		});//action listener
                
              
  
		getContentPane().add(cardPanel, BorderLayout.NORTH);
		getContentPane().add(buttonPanel, BorderLayout.SOUTH);
	
     }//Ttest()-close
        
     
   }
        
 
     public class Manager
     {
	public static void main(String[] args) {
		Ttest cl = new Ttest();
		cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		cl.setVisible(true);
	}
     }
